//
//  CustomCell.m
//  LoveHealth
//
//  Created by lanou3g on 14-9-23.
//  Copyright (c) 2014年 lanou. All rights reserved.
//

#import "CustomCell.h"

@interface CustomCell ()
{
    UIImageView * _backImageView;
}
- (void)p_setupSubviews;
@end
@implementation CustomCell
- (void)dealloc
{
    Block_release(_modalLoginBlock);
    
    [_backImageView release];
    self.imageViewArray = nil;
    self.headImageView = nil;
    self.qqLoginImageView = nil;
    self.sinaLoginImageView = nil;
    self.nameLabel = nil;
    [super dealloc];
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self p_setupSubviews];
    }
    return self;
}

- (void)p_setupSubviews
{
    _backImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, 210)];
    _backImageView.backgroundColor = [UIColor whiteColor];
    _backImageView.userInteractionEnabled = YES;
    _backImageView.image = [UIImage imageNamed:@"loginBGImg.JPG"];
    [self.contentView addSubview:_backImageView];
    
    _headImageView = [[UIImageView alloc] initWithFrame:CGRectMake((self.contentView.frame.size.width - 90)/2, 40, 100, 100)];
    _headImageView.backgroundColor = [UIColor blackColor];
    _headImageView.userInteractionEnabled = YES;
    [_backImageView addSubview:_headImageView];
    UIImage * image = [UIImage imageNamed:@"headDefault"];
    _headImageView.image = image;
    _headImageView.layer.cornerRadius = 50;
    _headImageView.clipsToBounds = YES;
    
    
    _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, _backImageView.bounds.size.height - 47, self.contentView.frame.size.width, 30)];
    _nameLabel.hidden = YES;
    _nameLabel.textAlignment = NSTextAlignmentCenter;
    [_backImageView addSubview:_nameLabel];
    
    
    _qqLoginImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10,_backImageView.bounds.size.height - 47, 140, 47)];
    _qqLoginImageView.image = [UIImage imageNamed:@"btn_qq_normal.png"];
    _qqLoginImageView.userInteractionEnabled = YES;
    [_backImageView addSubview:_qqLoginImageView];
    
    _sinaLoginImageView = [[UIImageView alloc] initWithFrame:CGRectMake(170, _backImageView.bounds.size.height - 47, 140, 47)];
    _sinaLoginImageView.userInteractionEnabled = YES;
    _sinaLoginImageView.image = [UIImage imageNamed:@"btn_sina_normal.png"];
    [_backImageView addSubview:_sinaLoginImageView];
    
    self.imageViewArray = @[_qqLoginImageView,_sinaLoginImageView];
    [self addTapGesture];
    
    
    
    
}

- (void)addTapGesture
{
    //遍历imageViewArray数组得到每个imageView对象
    for (UIImageView * view in self.imageViewArray) {
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTapGestureAction:)];
        //分别添加手势
        [view addGestureRecognizer:tap ];
        [tap release];
    }
}
//手势事件处理
- (void)handleTapGestureAction:(UITapGestureRecognizer *)tap
{
    //tap.view可以找到轻拍事件发上在那个视图上
    UIImageView * view = (UIImageView *)tap.view;
    if (view == self.qqLoginImageView) {
        
        self.modalLoginBlock(QQType);
        NSLog(@"qq");
    }else if(view == self.sinaLoginImageView){
   
        self.modalLoginBlock(SinaType);
        NSLog(@"sina");
    }  
}

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
